#include <cstdio>
#include <cstring>

int a[ 12 ], s[ 12 ], sum, tar, cnt;
bool ok1[ 12 ][ 12 ], ok2[ 12 ][ 12 ][ 12 ], ok3[ 12 ][ 12 ][ 12 ][ 12 ];
bool visit[ 12 ];

int init( )
{
    int i;
    sum = 0;
    for ( i = 0; i < 12; i++ )
    {
        scanf("%d", &a[ i ]);
        sum += a[ i ];
    }
    return sum;
}

void dfs( int step )
{
    int i;
    switch( step )
    {
        case 0:
            for ( i = 0; i < 12; i++ )
            {
                s[ step ] = i;
                visit[ i ] = true;
                dfs( step + 1 );
                visit[ i ] = false;
            }
            break;
        case 1:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok1[ s[ 0 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 2:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok2[ s[ 0 ] ][ s[ 1 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 3:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok3[ s[ 0 ] ][ s[ 1 ] ][ s[ 2 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 4:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok1[ s[ 1 ] ][ i ] && ok1[ s[ 2 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 5:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok2[ s[ 0 ] ][ i ] && ok2[ s[ 4 ] ][ s[ 1 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 6:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok2[ s[ 0 ] ][ i ] && ok3[ s[ 4 ] ][ s[ 1 ] ][ s[ 5 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 7:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok1[ s[ 3 ] ][ i ] && ok2[ s[ 4 ] ][ s[ 2 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 8:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok3[ s[ 4 ] ][ s[ 2 ] ][ s[ 7 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 9:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok2[ s[ 6 ] ][ s[ 8 ] ][ i ] && ok2[ s[ 0 ] ][ s[ 5 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 10:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok3[ s[ 6 ] ][ s[ 8 ] ][ s[ 9 ] ][ i ] && ok2[ s[ 3 ] ][ s[ 7 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 11:
            for ( i = 0; i < 12; i++ )
                if ( !visit[ i ] && ok3[ s[ 0 ] ][ s[ 5 ] ][ s[ 9 ] ][ i ] && ok3[ s[ 3 ] ][ s[ 7 ] ][ s[ 10 ] ][ i ] )
                {
                    s[ step ] = i;
                    visit[ i ] = true;
                    dfs( step + 1 );
                    visit[ i ] = false;
                }
            break;
        case 12:
            cnt++;
            break;
    }
}

void work( )
{
    int i1, i2, i3, i4;
    if ( sum % 3 != 0 )
    {
        puts("0");
        return ;
    }
    tar = sum / 3;
    memset( ok1, 0, sizeof( ok1 ) );
    memset( ok2, 0, sizeof( ok2 ) );
    memset( ok3, 0, sizeof( ok3 ) );
    for ( i1 = 0; i1 < 12; i1++ )
        for ( i2 = 0; i2 < 12; i2++ )
        {
            if ( i1 == i2 ) continue;
            for ( i3 = 0; i3 < 12; i3++ )
            {
                if ( i1 == i3 || i2 == i3 ) continue;
                for ( i4 = 0; i4 < 12; i4++ )
                {
                    if ( i1 == i4 || i2 == i4 || i3 == i4 ) continue;
                    if ( a[ i1 ] + a[ i2 ] + a[ i3 ] + a[ i4 ] == tar )
                        ok1[ i1 ][ i2 ] = ok2[ i1 ][ i2 ][ i3 ] = ok3[ i1 ][ i2 ][ i3 ][ i4 ] = true;
                }
            }
        }
    cnt = 0;
    memset( visit, 0, sizeof( visit ) );
    dfs( 0 );
    printf("%d\n", cnt / 12);
}

int main( )
{
    while ( init( ) )
    {
        work( );
    }
    return 0;
}
